/**
 * 部门管理初始化
 */
var DoctorLooked = {
    id: "DoctorLookedTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
DoctorLooked.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: 'customerId', field: 'customerId', visible: false, align: 'center', valign: 'middle'},
        {title: 'isStatus', field: 'isStatus', visible: false, align: 'center', valign: 'middle'},
        {title: 'reservationsId', field: 'reservationsId', visible: false, align: 'center', valign: 'middle'},
        {title: 'arrivalStore', field: 'arrivalStore', visible: false, align: 'center', valign: 'middle'},
        {title: 'tardyHour', field: 'tardyHour', visible: false, align: 'center', valign: 'middle'},
        {title: '患者姓名', field: 'customerName', align: 'center', valign: 'middle', sortable: true,
            formatter: function (value, row, index) {
                return "<a href='javascript:;' onclick='DoctorLooked.openBilee(" + '"' + row.customerId + '"' + ")'>"+row.customerName+"</a>"
            }
        },
        {
            title: '性别', field: 'customerSex', align: 'center', valign: 'middle', sortable: true,
            formatter: function (value, row, index) {
                if (value == 1) {
                    return "男";
                } else if (value == 2) {
                    return "女"
                }else{
                    return "未知"
                }
            }
        },
        {title: '年龄', field: 'customerAge', align: 'center', valign: 'middle', sortable: true},
        {title: '病历号', field: 'medicalRecordNumber', align: 'center', valign: 'middle', sortable: true},
        {
            title: '预约/挂号', field: 'arrivalTime', align: 'center', valign: 'middle', sortable: true,
            formatter: function (value, row, index) {
                return value.substring(11, 19);
            }
        },
        {title: '医生', field: 'doctor', align: 'center', valign: 'middle', sortable: true},
        {title: '预约项目', field: 'payServiceName', align: 'center', valign: 'middle', sortable: true},
        {title: '客户状态', field: 'customerStatus', align: 'center', valign: 'middle', sortable: true},
        {title: '就诊状态', field: 'arrivalStatus', align: 'center', valign: 'middle', sortable: true,
            formatter: function (value, row, index) {
                var strTime = (row.arrivalTime).replace("/-/g", "/");//时间转换
                var pastTime = new Date(strTime);  //时间
                var newTime = new Date();  //现在时间
                if(value == 2){
                    if (pastTime < newTime){return "<span>等待"+row.tardyHour+"</span>";}else {return "<span>已挂号</span>";}
                }else if(value == 3){
                    return "<span>治疗中</span>"
                }else if(value == 4){
                    return "<span>完成治疗</span>"
                }else if(value == 5){
                    return "<span>离开</span>"
                }else {
                    if (pastTime < newTime){return "<span>迟到" + row.tardyHour + "</span>";}else{return "<span>已预约</span>";}
                }
            },
            cellStyle:function(value, row, index){
                var strTime = (row.arrivalTime).replace("/-/g", "/");//时间转换
                var pastTime = new Date(strTime);  //时间
                var newTime = new Date();  //现在时间
                if(value == 2){
                    if(pastTime < newTime){
                        return {css:{"background-color":"#f95a3b","color":"white"}}
                    }else {
                        return {css:{"background-color":"#0d4b98","color":"white"}}
                    }
                }else if(value == 3){
                    return {css:{"background-color":"#fdc42d","color":"white"}}
                }else if(value == 4){
                    return {css:{"background-color":"#2cc87e","color":"white"}}
                }else if(value == 5){
                    return {css:{"background-color":"#a0a0a0","color":"white"}}
                }else {
                    return {}
                }
            }
        },
        {title: '就诊流程', field: 'arrivalStatus', align: 'center', valign: 'middle',width: '10%', sortable: true,
            formatter: function (value, row, index) {
                var sec = "";
                var ids = row.reservationsId + "," + row.customerId;
                if(index <= 1 ){
                    sec += '<div class="btn-group">';
                    if(value == 2){
                        sec +=  '<button type="button" class="btn btn-default surface" style="background: #ffffff;color: #333333;width:100px;margin: 0;" id="surface_'+row.customerId+'">开始治疗</button>';
                    }else if(value == 3){
                        sec +=  '<button type="button" class="btn btn-default surface" style="background: #ffffff;color: #333333;width:100px;margin: 0;" id="surface_'+row.customerId+'">完成治疗</button>';
                    }else if(value == 4){
                        sec +=  '<button type="button" class="btn btn-default surface" style="background: #ffffff;color: #333333;width:100px;margin: 0;" id="surface_'+row.customerId+'">离开</button>';
                    }else if(value == 5){
                        sec +=  '<button type="button" class="btn btn-default surface" style="background: #ffffff;color: #333333;width:100px;margin: 0;" id="surface_'+row.customerId+'">离开</button>';
                    }else{
                        sec +=  '<button type="button" class="btn btn-default surface" style="background: #ffffff;color: #333333;width:100px;margin: 0;" id="surface_'+row.customerId+'">开始治疗</button>';
                    }
                }else {
                    sec += '<div class="btn-group dropup">';
                    if(value == 2){
                        sec +=  '<button type="button" class="btn btn-default surface" style="background: #ffffff;color: #333333;width:100px;margin: 0;" id="surface_'+row.customerId+'">开始治疗</button>';
                    }else if(value == 3){
                        sec +=  '<button type="button" class="btn btn-default surface" style="background: #ffffff;color: #333333;width:100px;margin: 0;" id="surface_'+row.customerId+'">完成治疗</button>';
                    }else if(value == 4){
                        sec +=  '<button type="button" class="btn btn-default surface" style="background: #ffffff;color: #333333;width:100px;margin: 0;" id="surface_'+row.customerId+'">离开</button>';
                    }else if(value == 5){
                        sec +=  '<button type="button" class="btn btn-default surface" style="background: #ffffff;color: #333333;width:100px;margin: 0;" id="surface_'+row.customerId+'">离开</button>';
                    }else{
                        sec +=  '<button type="button" class="btn btn-default surface" style="background: #ffffff;color: #333333;width:100px;margin: 0;" id="surface_'+row.customerId+'">开始治疗</button>';
                    }
                }
                sec += '<button type="button" class="btn btn-default dropdown-toggle" style="background: #ffffff;color: #333333;margin: 0;" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="caret"></span></button>'+
                    '<ul class="dropdown-menu" style="min-width: 99%;text-align: center;">' ;
                if(row.arrivalStatus==3){
                    sec +=   '<li class="dropdown-header"  style="background-color:#F2F2F2;color:#ADA6A6;" >挂号</li>' +
                        '<li class="dropdown-header" style="background-color:#F2F2F2;color:#ADA6A6;" >开始治疗</li>' +
                        '<li onclick="DoctorLooked.completionTreatment('+"'"+row.customerName+"','"+row.customerId+"','"+row.doctor+"','"+row.arrivalTime+"'"+')">完成治疗</li>'+
                        '<li onclick="DoctorLooked.alreadyLeave('+"'"+row.customerId+"','"+row.customerName+"'"+')">离开</li>'+
                        '<li onclick="DoctorLooked.returnTo('+"'"+row.customerId+"','"+row.customerName+"'"+')">回退</li>';
                }else if(row.arrivalStatus==4){
                    sec +=   '<li class="dropdown-header"  style="background-color:#F2F2F2;color:#ADA6A6;" >挂号</li>' +
                        '<li class="dropdown-header" style="background-color:#F2F2F2;color:#ADA6A6;" >开始治疗</li>' +
                        '<li class="dropdown-header" style="background-color:#F2F2F2;color:#ADA6A6;" >完成治疗</li>' +
                        '<li onclick="DoctorLooked.alreadyLeave('+"'"+row.customerId+"','"+row.customerName+"'"+')">离开</li>'+
                        '<li onclick="DoctorLooked.returnTo('+"'"+row.customerId+"','"+row.customerName+"'"+')">回退</li>';
                }else if(row.arrivalStatus==5){
                    sec +='<li onclick="DoctorLooked.regresses('+"'"+row.customerId+"','"+row.customerName+"'"+')">挂号</li>' +
                        '<li class="dropdown-header" style="background-color:#F2F2F2;color:#ADA6A6;" >开始治疗</li>' +
                        '<li class="dropdown-header" style="background-color:#F2F2F2;color:#ADA6A6;" >完成治疗</li>' +
                        '<li class="dropdown-header" style="background-color:#F2F2F2;color:#ADA6A6;">离开</li>'+
                        '<li onclick="DoctorLooked.returnTo('+"'"+row.customerId+"','"+row.customerName+"'"+')">回退</li>';
                }else{
                    sec +='<li onclick="DoctorLooked.regresses('+"'"+row.customerId+"','"+row.customerName+"'"+')">挂号</li>' +
                        '<li onclick="DoctorLooked.startTreatment('+"'"+row.customerId+"','"+row.customerName+"'"+')">开始治疗</li>' +
                        '<li onclick="DoctorLooked.completionTreatment('+"'"+row.customerName+"','"+row.customerId+"','"+row.doctor+"','"+row.arrivalTime+"'"+')">完成治疗</li>'+
                        '<li onclick="DoctorLooked.alreadyLeave('+"'"+row.customerId+"','"+row.customerName+"'"+')">离开</li>'+
                        '<li class="dropdown-header" style="background-color:#F2F2F2;color:#ADA6A6;")">回退</li>';
                }
                sec +='</ul></div>';
                return sec;
            }
        },
        {
            title: '操作', field: 'id', align: 'center', valign: 'middle', sortable: true, width: '12%',
            formatter: function (value, row, index) {
                var ids = row.reservationsId + "," + row.customerId;
                if(row.isStatus==1){
                    return '<button title="添加随访时间" onclick="DoctorLooked.followRevision('+"'"+row.customerId+"','"+row.customerName+"','"+row.reservationsId+"','"+row.arrivalStore+"'"+')" type="button" class="btn" style="background: #ffffff;border: 1px solid #cccccc;"><span class="glyphicon glyphicon-earphone"></span></button>' +
                        '<button title="创建新建预约" onclick="DoctorLooked.appointment('+"'"+row.customerId+"','"+row.reservationsId+"','"+row.doctor+"'"+')" type="button" class="btn" style="background: #ffffff;border: 1px solid #cccccc;"><span class="glyphicon glyphicon-plus"></span></button>'+
                        '<button title="添加病历" onclick="DoctorLooked.openBilee(' + "'" + row.customerId + "'" + ')" type="button" class="btn" style="background: #ffffff;border: 1px solid #cccccc;"><span class="glyphicon glyphicon-file" style="color: green"></span></button>'+
                        '<button title="添加就诊详情" onclick="DoctorLooked.doctor_editors('+"'"+row.customerId+"','"+row.arrivalTime+"','"+row.doctor+"'"+')" type="button" class="btn" style="background: #ffffff;border: 1px solid #cccccc;"><span class="glyphicon glyphicon-plus-sign"></span></button>'
                }else {
                    return '<button title="添加随访时间" onclick="DoctorLooked.followRevision('+"'"+row.customerId+"','"+row.customerName+"','"+row.reservationsId+"','"+row.arrivalStore+"'"+')" type="button" class="btn" style="background: #ffffff;border: 1px solid #cccccc;"><span class="glyphicon glyphicon-earphone"></span></button>' +
                        '<button title="创建新建预约" onclick="DoctorLooked.appointment('+"'"+row.customerId+"','"+row.reservationsId+"','"+row.doctor+"'"+')" type="button" class="btn" style="background: #ffffff;border: 1px solid #cccccc;"><span class="glyphicon glyphicon-plus"></span></button>'+
                        '<button title="添加病历" onclick="DoctorLooked.openBilee(' + "'" + row.customerId + "'" + ')" type="button" class="btn" style="background: #ffffff;border: 1px solid #cccccc;"><span class="glyphicon glyphicon-file"></span></button>'+
                        '<button title="添加就诊详情" onclick="DoctorLooked.doctor_editors('+"'"+row.customerId+"','"+row.arrivalTime+"','"+row.doctor+"'"+')" type="button" class="btn" style="background: #ffffff;border: 1px solid #cccccc;"><span class="glyphicon glyphicon-plus-sign"></span></button>'
                }
            }
        },
    ]
    return columns;
};

/**
 * 点击挂号
 */
DoctorLooked.regresses = function (customerId,customerName) {
    if(confirm("患者【"+customerName+"】已挂号?")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/regresses",
            type: "post",
            data: {
                customerId: customerId
            },
            success: function (data) {
                Feng.success('操作成功!');
                //document.getElementById("surface_"+customerId).innerHTML = "挂号";
                DoctorLooked.inquire()
            },
            error: function (data) {
                alert('内部故障!');
            }
        });
    }
};
/**
 * 点击开始治疗
 */
DoctorLooked.startTreatment = function (customerId,customerName) {
    if(confirm("患者【"+customerName+"】已经开始治疗?")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/startTreatment",
            type: "post",
            data: {
                customerId: customerId
            },
            success: function (data) {
                Feng.success('操作成功!');
                //document.getElementById("surface_"+customerId).innerHTML = "开始治疗";
                DoctorLooked.inquire()
            },
            error: function (data) {
                alert('内部故障!');
            }
        });
    }
};
/**
 * 点击完成治疗
 */
DoctorLooked.completionTreatment = function (customerName,customerId,doctor,arrivalTime) {
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/completionTreatment",
        type: "post",
        data: {
            customerId: customerId
        },
        success: function (data) {
            //document.getElementById("surface_"+customerId).innerHTML = "离开";
            DoctorLooked.inquire()
        },
        error: function (data) {
            alert('内部故障!');
        }
    });
   /* if(confirm("是否去添加就诊记录")) {
        var cad = doctor +","+customerId +","+arrivalTime;
        var index = layer.open({
            type: 2,
            title: '添加就诊记录',
            area: ['50%', '100%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/doctorLooked/doctor_editors/'+ cad
        });
        this.layerIndex = index;
    }*/
};
/**
 * 点击离开
 */
DoctorLooked.alreadyLeave = function (customerId,customerName) {
    if(confirm("确定患者【"+customerName+"】已经离开?")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/alreadyLeave",
            type: "post",
            data: {
                customerId: customerId
            },
            success: function (data) {
                Feng.success('操作成功!');
                //document.getElementById("surface_"+customerId).innerHTML = "已离开";
                DoctorLooked.inquire()
            },
            error: function (data) {
                alert('内部故障!');
            }
        });
    }
};

/**
 * 点击回退
 */
DoctorLooked.returnTo = function (customerId,customerName) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/returnTo",
            type: "post",
            data: {
                customerId: customerId
            },
            success: function (data) {
                Feng.success('操作成功!');
                // var type = data.substring(3,4);
                // if(type == 3){
                //     document.getElementById("surface_"+customerId).innerHTML = "开始治疗";
                // }else if(type == 4){
                //     document.getElementById("surface_"+customerId).innerHTML = "完成治疗";
                // }
                DoctorLooked.inquire()
            },
            error: function (data) {
                alert('内部故障!');
            }
        });
};
/**
 * 添加随访时间
 */
DoctorLooked.followRevision = function (customerId,customerName,reservationsId,arrivalStore) {
    var cri=customerId+","+reservationsId+","+arrivalStore;
    var index = layer.open({
        type: 2,
        title: '添加随访时间',
        area: ['50%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/alreadyLeave/'+cri
    });
    this.layerIndex = index;
};

DoctorLooked.appointment = function (customerId,reservationsId,doctor) {
    var cid = customerId + "," + reservationsId + "," + doctor;
    var index = layer.open({
        type: 2,
        title: '新建预约',
        area: ['60%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/doctor_appointment/' + cid
    });
    this.layerIndex = index;
};
//添加就诊详情
DoctorLooked.doctor_editors = function (customerId,arrivalTime,doctor) {
    var cad = doctor + "," + customerId + "," + arrivalTime;
    var index = layer.open({
        type: 2,
        title: '添加就诊详情',
        area: ['50%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/doctor_editors/' + cad
    });
    this.layerIndex = index;
}


/**
 * 点击姓名查看详情
 */
DoctorLooked.openBilee = function (id) {
    var index = layer.open({
        type: 2,
        title: '患者信息',
        area: ['100%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/doctor_seeDiagnosis/' + id
    });
    this.layerIndex = index;
};



/**
 * 市场录入详情
 */
DoctorLooked.openscDetail = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '预约客户详情',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservations/reservations_details/' + reservationsId
    });
    this.layerIndex = index;
};

/**
 * 前台录入详情
 */
DoctorLooked.openqtDetail = function (id) {
    var index = layer.open({
        type: 2,
        title: '预约客户详情',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/customer_details/' + id
    });
    this.layerIndex = index;
};

/**
 * 医生开病例弹出框
 * @param id
 */
DoctorLooked.caseRecord = function (id) {
    var index = layer.open({
        type: 2,
        title: '病历列表',
        area: ['100%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/caseInfoPage/'+id
    });
    this.layerIndex = index;
};

/**
 * 医生划价
 * @param id
 */
DoctorLooked.changePrice = function () {
    if(this.check()){
        var index = layer.open({
            type: 2,
            title: '医生划价详情',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/doctorLooked/change_price/'+DoctorLooked.seItem.reservationsId
        });
        this.layerIndex = index;
    }
};

DoctorLooked.openAddVisited = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '添加回访记录',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/to_addVisited/' + reservationsId
    });
    this.layerIndex = index;
};

DoctorLooked.openRevisit = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '预约回访详情',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/openRevisit/' + reservationsId
    });
    this.layerIndex = index;
};

DoctorLooked.openNoRevisit = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '不回访原因',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/openNoRevisit/' + reservationsId
    });
    this.layerIndex = index;
};

DoctorLooked.openRevisitRecord = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '回访记录',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/to_revisitRecord/' + reservationsId
    });
    this.layerIndex = index;
};

DoctorLooked.updateDiagnosisDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '看诊详情',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/doctorLooked/doctorLooked_update/' + DoctorLooked.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 打开看诊详情
 */
DoctorLooked.setDiagnosisRecord = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '看诊记录',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/diagnosis_details/' + reservationsId
    });
    this.layerIndex = index;
};

DoctorLooked.toComment = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '医生点评',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/doctorLooked/to_doctor_comment/' + DoctorLooked.seItem.id
        });
        this.layerIndex = index;
    }
};

// DoctorLooked.revisitOperations = function (reservationsId) {
//     var index = layer.open({
//         type: 2,
//         title: '回访操作',
//         area: ['90%', '90%'], //宽高
//         fix: true, //不固定
//         maxmin: true,
//         content: Feng.ctxPath + '/doctorLooked/to_revisitOperation/' + reservationsId
//     });
//     this.layerIndex = index;
// };

/**
 * 检查是否选中
 */
DoctorLooked.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        DoctorLooked.seItem = selected[0];
        return true;
    }
};

/**
 * 查询预约客户列表
 */
DoctorLooked.search = function () {
    DoctorLooked.table.refresh({query: DoctorLooked.formParams()});
    DoctorLooked.table.refresh({query: DoctorLooked.formParams()});
    DoctorLooked.total()
};

DoctorLooked.resetSearch = function () {
    $("#reach").val("");
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#arrivalTime").val("");
    $("#endRevisitTime").val("");
    $("#isReturnVisit").val("");
    $("#doctor").val("");
    $("#customerStatus").val("");
    $("#fieldTc").val("");
    $("#customerSex").val("");
    $("#payServiceName").val("");
    $("#customerAgeStart").val("");
    $("#customerAgeEnd").val("");
    document.getElementById("arrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day ;
    DoctorLooked.inquire()
};

DoctorLooked.inquire = function () {
    // document.getElementById("doctorValue").value=document.getElementById("doctor").value;
    DoctorLooked.search();
    DoctorLooked.total();
};

DoctorLooked.close = function () {
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.close(index);
};

/**
 * 统计
 */
DoctorLooked.total = function () {
    var param1 = $("#arrivalTime").val();  //预约到店时间
    var param2 = $("#doctorValue").val();
    var payServiceName = $("#payServiceName").val();
    var customerSex = $("#customerSex").val();
    var customerAgeStart = $("#customerAgeStart").val();
    var customerAgeEnd = $("#customerAgeEnd").val();
    $.ajax({
        type: "GET",
        url: Feng.ctxPath + "/doctorLooked/total",
        data: {
            param1: param1, param2: param2,
            payServiceName: payServiceName, customerSex: customerSex,
            customerAgeStart:customerAgeStart,customerAgeEnd:customerAgeEnd
        },
        dataType: "json",
        success: function (data) {
            $("#all").html(data[0].countNum);//总人数
            $("#non-arrival").html(data[1].countNum);//未到
            $("#yi-arrived").html(data[2].countNum);//已到
            $("#treatMent").html(data[3].countNum);//就诊中
            $("#see-doctor").html(data[4].countNum);//完成治疗

        }
    });
};
/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
DoctorLooked.formParams = function () {
    var queryData = {};
    queryData['reach'] = $("#reach").val();
    queryData['arrivalTime'] = $("#arrivalTime").val();
    queryData['doctor'] = $("#doctorValue").val();
    queryData['customerSex'] = $("#customerSex").val();
    queryData['payServiceName'] = $("#payServiceName").val();
    queryData['customerAgeStart'] = $("#customerAgeStart").val();
    queryData['customerAgeEnd'] = $("#customerAgeEnd").val();
    return queryData;
};
//查询全部
DoctorLooked.allNum=function () {
    var queryData = {};
    queryData['reach'] = $("#reach").val();
    queryData['arrivalTime'] = $("#arrivalTime").val();
    queryData['doctor'] = $("#doctorValue").val();
    queryData['customerSex'] = $("#customerSex").val();
    queryData['payServiceName'] = $("#payServiceName").val();
    queryData['customerAgeStart'] = $("#customerAgeStart").val();
    queryData['customerAgeEnd'] = $("#customerAgeEnd").val();
    queryData['arrivalStatus'] = "";
    DoctorLooked.table.refresh({query: queryData});
}
//查询未到
DoctorLooked.noNum=function () {
    var queryData = {};
    queryData['reach'] = $("#reach").val();
    queryData['arrivalTime'] = $("#arrivalTime").val();
    queryData['doctor'] = $("#doctorValue").val();
    queryData['customerSex'] = $("#customerSex").val();
    queryData['payServiceName'] = $("#payServiceName").val();
    queryData['customerAgeStart'] = $("#customerAgeStart").val();
    queryData['customerAgeEnd'] = $("#customerAgeEnd").val();
    queryData['arrivalStatus'] = "1";
    DoctorLooked.table.refresh({query: queryData});
}
//查询已到
DoctorLooked.yesNum=function () {
    var queryData = {};
    queryData['reach'] = $("#reach").val();
    queryData['arrivalTime'] = $("#arrivalTime").val();
    queryData['doctor'] = $("#doctorValue").val();
    queryData['customerSex'] = $("#customerSex").val();
    queryData['payServiceName'] = $("#payServiceName").val();
    queryData['customerAgeStart'] = $("#customerAgeStart").val();
    queryData['customerAgeEnd'] = $("#customerAgeEnd").val();
    queryData['arrivalStatus'] = "2";
    DoctorLooked.table.refresh({query: queryData});

}
//查询就诊中
DoctorLooked.treatMentNum=function () {
    var queryData = {};
    queryData['reach'] = $("#reach").val();
    queryData['arrivalTime'] = $("#arrivalTime").val();
    queryData['doctor'] = $("#doctorValue").val();
    queryData['customerSex'] = $("#customerSex").val();
    queryData['payServiceName'] = $("#payServiceName").val();
    queryData['customerAgeStart'] = $("#customerAgeStart").val();
    queryData['customerAgeEnd'] = $("#customerAgeEnd").val();
    queryData['arrivalStatus'] = "3";
    DoctorLooked.table.refresh({query: queryData});

}
//查询完成治疗
DoctorLooked.okNum=function () {
    var queryData = {};
    queryData['reach'] = $("#reach").val();
    queryData['arrivalTime'] = $("#arrivalTime").val();
    queryData['doctor'] = $("#doctorValue").val();
    queryData['customerSex'] = $("#customerSex").val();
    queryData['payServiceName'] = $("#payServiceName").val();
    queryData['customerAgeStart'] = $("#customerAgeStart").val();
    queryData['customerAgeEnd'] = $("#customerAgeEnd").val();
    queryData['arrivalStatus'] = "4";
    DoctorLooked.table.refresh({query: queryData});
}

var myDate = new Date();
var month;
var day;
if ((myDate.getMonth() + 1) < 10) {
    month = "0" + (myDate.getMonth() + 1);
} else {
    month = "" + (myDate.getMonth() + 1);
}
if (myDate.getDate() < 10) {
    day = "0" + myDate.getDate();
} else {
    day = "" + myDate.getDate();
}
$("#next").click(function () {
    var stime = document.getElementById("arrivalTime").value;
    var date = new Date(stime);
    var monthe;
    var daye;
    if (stime.length == 7) {
        date.setMonth(date.getMonth() + 1);
        if ((date.getMonth() + 1) < 10) {
            monthe = "0" + (date.getMonth() + 1);
        } else {
            monthe = "" + (date.getMonth() + 1);
        }
        document.getElementById("arrivalTime").value = date.getFullYear() + "-" + monthe;
    }
    if (stime.length == 10) {
        date.setDate(date.getDate() + 1);
        if ((date.getMonth() + 1) < 10) {
            monthe = "0" + (date.getMonth() + 1);
        } else {
            monthe = "" + (date.getMonth() + 1);
        }
        if (date.getDate() < 10) {
            daye = "0" + date.getDate();
        } else {
            daye = "" + date.getDate();
        }
        //// 加一天
        document.getElementById("arrivalTime").value = date.getFullYear() + "-" + monthe + "-" + daye;
    }
})
$("#minus").click(function () {
    var stime = document.getElementById("arrivalTime").value;
    var date = new Date(stime);
    var monthe;
    var daye;
    if (stime.length == 7) {
        date.setMonth(date.getMonth() - 1);
        if ((date.getMonth() + 1) < 10) {
            monthe = "0" + (date.getMonth() + 1);
        } else {
            monthe = "" + (date.getMonth() + 1);
        }
        document.getElementById("arrivalTime").value = date.getFullYear() + "-" + monthe;
    }
    if (stime.length == 10) {
        date.setDate(date.getDate() - 1);
        if ((date.getMonth() + 1) < 10) {
            monthe = "0" + (date.getMonth() + 1);
        } else {
            monthe = "" + (date.getMonth() + 1);
        }
        if (date.getDate() < 10) {
            daye = "0" + date.getDate();
        } else {
            daye = "" + date.getDate();
        }
        //// 加一天
        document.getElementById("arrivalTime").value = date.getFullYear() + "-" + monthe + "-" + daye;
    }
});
$(function () {
    // $.ajax({
    //     url: Feng.ctxPath + "/consultant/getDoctor",
    //     type: "get",
    //     success: function (data) {
    //         var txt = '<option value="">--请选择医生--</option>';
    //         for (var i = 0; i < data.length; i++) {
    //             txt += '<option value="' + data[i].doctor + '">' + data[i].doctor + '</option>';
    //         }
    //         document.getElementById('doctor').innerHTML = txt;
    //         //状态单选
    //         var seleteDoctorValue = $('#doctorValue').val();
    //         if (seleteDoctorValue != "") {
    //             $("#doctor option[value=" + seleteDoctorValue + "]").attr("selected", "selected");
    //         }
    //     },
    //     error: function (data) {
    //         alert('内部故障!');
    //     }
    // });
    document.getElementById("arrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day;
    var stime = document.getElementById("arrivalTime").value;
    var mtime = stime.substring(0, 7)
    $(".btn2").click(function () {
        $("#arrivalTime").val(mtime)
        $("#arrivalTime").attr("disabled", true)
    })
    $(".btn3").click(function () {
        $("#arrivalTime").val(stime)
        $("#arrivalTime").attr("disabled", false)
    });
    var defaultColunms = DoctorLooked.initColumn();
    var table = new BSTable(DoctorLooked.id, "/doctorLooked/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(DoctorLooked.formParams());
    DoctorLooked.table = table.init();
    DoctorLooked.search();
    DoctorLooked.total();
    $(".fixed-table-body").css({height:$(window).height()-310});
    //采用定时器监听 时间内容是否变化
    var oldStartValue = $("#arrivalTime").val();

    var customerAgeStartValue = $("#customerAgeStart").val();
    var customerAgeEndValue = $("#customerAgeEnd").val();

    setInterval(
        function () {//定时执行方法内容
            if ($("#arrivalTime").val() != oldStartValue) {//如果时间发生变化，就触发查询事件
                DoctorLooked.search();
                DoctorLooked.total();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                oldStartValue = $("#arrivalTime").val();
            }
            if ($("#customerAgeStart").val() != customerAgeStartValue || $("#customerAgeEnd").val() != customerAgeEndValue) {//如果时间发生变化，就触发查询事件
                DoctorLooked.search();
                DoctorLooked.total();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                customerAgeStartValue = $("#customerAgeStart").val();
                customerAgeEndValue = $("#customerAgeEnd").val();
            }

        }, 500);
});




